﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLFacade.entities;

namespace ProjectUI
{
    public partial class ContactListForm : Form
    {
        private ICustomer customer;
        public ContactListForm()
        {
            InitializeComponent();
        }

        public ContactListForm(ICustomer customer)
        {
            InitializeComponent();
            gridViewContacts.AutoGenerateColumns = false;
            this.customer = customer;
            gridViewContacts.DataSource = customer.Contacts;
            this.Text = String.Format("Contacts of {0}", customer.Name);
        }

        private void gridViewContacts_DoubleClick(object sender, EventArgs e)
        {
            int index = gridViewContacts.SelectedCells[0].RowIndex;
            CustomerContactForm info = new CustomerContactForm(((List<ICustomerContacts>)gridViewContacts.DataSource)[index]);
            info.MdiParent = this.MdiParent;
            info.Show();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            CustomerContactForm info = new CustomerContactForm(customer);
            info.MdiParent = this.MdiParent;
            info.Show();
            this.Close();
        }

        //public void UpdateDataSource()
        //{
        //    gridViewContacts.DataSource = customer.Contacts;
        //}
    }
}
